<?php
namespace shenyewangyue\Jt808;
use shenyewangyue\Jt808\Jt808;

class Jt0704{
    public $mesageBody = [];
    public $jt808;
    public $jt0200;
    public function __construct($data)
    {
        $this->mesageBody = $data;
        $this->jt808 = new Jt808();

    }
    public function getJt0704Data(){
        $mesageBodyArray = [
            'smsNum' => $this->getSmsNum(),
            'smsType' => $this->getSmsType(),
            'smsBodydata' => $this->getSmsBodydata(),
        ];
        return $mesageBodyArray;
    }
    public function getSmsNum(){
        $smsNum = array_slice($this->mesageBody, 0, 2);
        $smsNum = $this->jt808->twoBytesToInteger($smsNum);
        $smsNum = (int)$smsNum;
        return $smsNum;
    }
    public function getSmsType(){
        $smsType = array_slice($this->mesageBody,2,1);
        $smsType = $this->jt808->ArrayToString($smsType);
        return $smsType;
    }
//    public function getSmsBodyLength(){
//        $smsBodyLength = array_slice($this->mesageBody,3,2);
//        $smsBodyLength = $this->jt808->twoBytesToInteger($smsBodyLength);
//        return $smsBodyLength;
//    }
    public function getSmsBodydata(){
//00 22
//00 00 00 00 00 00 00 03 02 61 ca d6 06 ef 1f 0e 00 01 00 00 00 00 20 12 16 15 04 12 01 04 00 00 03 cd
//00 22
//00 00 00 00 00 00 00 03 02 61 ca d6 06 ef 1f 0e 00 01 00 00 00 00 20 12 16 15 04 13 01 04 00 00 03 cd
//00 22
//00 00 00 00 00 00 00 03 02 61 ca d6 06 ef 1f 0e 00 01 00 00 00 00 20 12 16 15 04 15 01 04 00 00 03 cd
//00 22
//00 00 00 00 00 00 00 03 02 61 ca d6 06 ef 1f 0e 00 01 00 00 00 00 20 12 16 15 04 16 01 04 00 00 03 cd
//00 22
//00 00 00 00 00 00 00 03 02 61 ca d6 06 ef 1f 0e 00 01 00 00 00 00 20 12 16 15 04 17 01 04 00 00 03 cd
        $smsBody = array_slice($this->mesageBody,3);
        $smsBodyArray = [];
//        $smsBodyArray['smsBody'] = $smsBody;
        $i = 0;
        $i_length = 0;
        $smsNum = $this->getSmsNum();
        $smsBodyArray['smsNum'] = $smsNum;
        while($i < $smsNum){
            $length_arr = array_slice($smsBody,$i_length,2);
            $length = $this->jt808->twoBytesToInteger($length_arr);
            $length = $length + 0;
            $i_length = $i_length + 2;
            $body = array_slice($smsBody,$i_length,$length);
            $i_length = $i_length + $length;
            $jt0200 = new Jt0200($body);
//            $smsBodyArray['data'][$i]['length_arr'] = $length_arr;
            $smsBodyArray['data'][$i]['length'] = $length;
//            $smsBodyArray['data'][$i]['body'] = $body;
            $smsBodyArray['data'][$i]['bodyArray'] = $jt0200->getJt0200Data();

            $i++;
        }
        return $smsBodyArray;

//        return $smsBodyLength;
    }
}
?>